<template>
  <div class="mod-order-return">
    <el-form
      :inline="true"
      :model="dataForm"
      @keyup.enter="getDataList(page)"
    >
      <el-form-item label="服务单号:">
        <el-input
          v-model="dataForm.refundSn"
          placeholder="服务单号"
          clearable
        />
      </el-form-item>
      <el-form-item label="处理状态:">
        <el-select
          v-model="dataForm.refundSts"
          clearable
          placeholder="请选择处理状态"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请时间:">
        <el-date-picker
          v-model="dataForm.applyTime"
          type="date"
          placeholder="请选择时间"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item label="处理时间:">
        <el-date-picker
          v-model="dataForm.handelTime"
          type="date"
          placeholder="请选择时间"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="getDataList()"
        >
          查询
        </el-button>
        <!-- <el-button
          v-if="isAuth('order:order:waitingConsignmentExcel')"
          type="primary"
          @click="showConsignmentInfo()"
        >
          导出待发货订单
        </el-button>
        <el-button
          v-if="isAuth('order:order:soldExcel')"
          type="primary"
          @click="getSoldExcel()"
        >
          导出销售记录
        </el-button> -->
        <el-button @click="clearDatas()">
          清空
        </el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border style="width: 100%" >
      <el-table-column prop="refundSn" label="服务单号" align="center" />
      <el-table-column prop="applyTime" label="申请时间" align="center" />
      <!-- <el-table-column prop="commitUser" label="用户账号" align="center" /> -->
      <el-table-column prop="refundAmount" label="退款金额" align="center" />
      <el-table-column prop="refundSts" label="申请状态" align="center">
        <template #default="scope">
          <span v-if="scope.row.refundSts===1">待审核</span>
          <span v-else-if="scope.row.refundSts===2">同意</span>
          <span v-else>不同意</span>
        </template>
      </el-table-column>
      <el-table-column prop="returnMoneySts" label="退款状态" align="center">
        <template #default="scope">
          <span v-if="scope.row.returnMoneySts===0">退款处理中</span>
          <span v-else-if="scope.row.returnMoneySts===1">退款成功</span>
          <span v-else>退款失败</span>
        </template>
      </el-table-column>
      <el-table-column prop="handelTime" label="处理时间" align="center" />
      <el-table-column label="操作" width="120" align="center">
        <template #default="scope">
          <el-button type="text" @click="onAddOrUpdate(scope.row.refundId)"
            >查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="page.pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="page.pageSize"
      :total="page.total"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
    />
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdateRef"
      @refresh-data-list="getDataList"
    />
  </div>
</template>

<script setup>
import AddOrUpdate from './components/add-or-update.vue'
const dataForm = ref({})
const options = [{
  value: 1,
  label: '待审核'
},
{
  value: 2,
  label: '同意'
},
{
  value: 3,
  label: '不同意'
}]
const dataList = ref([
  {
    refundSn: '1',
    applyTime: '2024-8-20',
    commitUser: 'test',
    refundAmount: '100',
    refundSts: '1',
    handelTime: null
  }
])
const page = reactive({
  total: 0, // 总页数
  currentPage: 1, // 当前页数
  pageSize: 10 // 每页显示多少条
})

onMounted(() => {
  getDataList(page)
})

/**
 * 获取数据列表
 */
const getDataList = (pageParam, params, done) => {
  pageParam = (pageParam === undefined ? page : pageParam)
  // console.log('沙拉', pageParam)
  http({
    url: http.adornUrl('/order/return/page'),
    method: 'get',
    params: http.adornParams(
      Object.assign(
        {
          current: pageParam == null ? page.currentPage : pageParam.currentPage,
          size: pageParam == null ? page.pageSize : pageParam.pageSize,
          refundSn: dataForm.value.refundSn,
          refundSts: dataForm.value.refundSts,
          applyTime: dataForm.value.applyTime,
          handelTime: dataForm.value.handelTime
        },
        params
      ), false
    )
  })
    .then(({ data }) => {
      dataList.value = data.records
      page.total = data.total
      if (done) done()
    })
}
/**
 * 清除数据
 */
const clearDatas = () => {
  dataForm.value = {}
}
/**
 * 每页数
 * @param val
 */
const sizeChangeHandle = (val) => {
  page.pageSize = val
  page.currentPage = 1
  getDataList(page)
}
/**
 * 当前页
 * @param val
 */
const currentChangeHandle = (val) => {
  page.currentPage = val
  getDataList(page)
}
const addOrUpdateRef = ref(null)
const addOrUpdateVisible = ref(false)
/**
 * 新增 / 修改
 * @param val
 */
const onAddOrUpdate = (val) => {
  addOrUpdateVisible.value = true
  nextTick(() => {
    addOrUpdateRef.value?.init(val)
  })
}
</script>

<style lang="scss" scoped>
// .mod-order-return {

// }
</style>
